//server
#include <iostream>
#include <winsock.h>
using namespace std;
DWORD WINAPI ConnectClient(LPVOID param)
{
    SOCKET NewSoccet;
    NewSoccet= *(SOCKET *)param;
 
        char n = 0;
        recv(NS,&n,1,0);
        cout<<"Received Length = "<< int(n) <<"\n";
        char* a=new char[100];
        recv(NS,a,n,0);
        cout<<"Received: \"";
        for (int i=0;i<n;i++) { cout<<a[i]; }
        cout<<"\"\n";
        closesocket(NewSoccet);  
 
    return 0;
}
int main()
{   
    WSAData WSData; 
    WSAStartup(0x202,&WSData); 
    SOCKET Server = socket(AF_INET,SOCK_STREAM,0); 
    sockaddr_in SA;
    SA.sin_family=AF_INET;  
    SA.sin_port=htons(3135);
    SA.sin_addr.S_un.S_addr=INADDR_ANY;    
    bind(S,(sockaddr*)&SA,sizeof(SA)); 
    listen(Server,SOMAXCONN); 
    SOCKET NewSoccet;	
    while ((NS = accept(S,0,0))!=INVALID_SOCKET)
    {        
       cout<<"Connected...\n";
       DWORD thID;
       CreateThread(NULL, NULL, ConnectClient, &NewSoccet, NULL, &thID);    
    }
    closesocket(Server); 
}